package com.vibration.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.vibration.common.utils.http.HttpUtils;

public class CardFlowAPI {

    static String  tokenUrl = "https://sim.usr.cn/api/v1.Token/getTokenByAppKey";
    static String  simUrl = "https://sim.usr.cn/api/v1.AssetCard/getAssetCardList";

    static String appkey = "f5c17bcc7a6e767d40b213fab1c897e6";
    static String token = "fe8afbf735c052abb82d0bc89078dc70";

    public static String login() {
        JsonObject pa=new JsonObject();
        pa.addProperty("appkey", appkey);
        pa.addProperty("token", token);
        return HttpUtils.sendSSLPost(tokenUrl,pa.toString(),null);
    }
    public static String haveCardList(String token) {
        JsonObject pa=new JsonObject();
        //pa.addProperty("token", token);
        pa.addProperty("offset", 0);
        pa.addProperty("limit", 1000);
        return HttpUtils.sendSSLPost(simUrl,pa.toString(),token);
    }

    public static void main(String[] args) {
       // System.err.println(login());
        JSONObject loginObj = JSONObject.parseObject(login());
        String token="";
        if(200 == loginObj.getInteger("status")){
            JSONObject dataObj=loginObj.getJSONObject("data");
            token = dataObj.getString("token");
            System.err.println(token);
        }
        JSONObject cardObj = JSONObject.parseObject(haveCardList(token));
        if(200 == cardObj.getInteger("status")){
            JSONObject cardDataObj=cardObj.getJSONObject("data");
            JSONArray dataList = cardDataObj.getJSONArray("list");
            System.err.println(dataList);
        }
    }
}
